import java.awt.*;
import java.awt.image.BufferedImage;

import com.golden.gamedev.*;
import com.golden.gamedev.object.*;
import com.golden.gamedev.object.background.*;


public class TitleScreen extends GameObject{
	private GameFont myFont;
	private Sprite myButton;
	private Sprite resumeButton;
	private String myTitle;
	private Background myBackground;
	public TitleScreen(GameEngine engine) {
		super(engine);
	}

	@Override
	public void initResources() 
	{
		myTitle = "Bounce Game";
		BufferedImage buttonImage = getImage("images/newGame.png");
	    myBackground = new ImageBackground(getImage("images/bounceGameBack.png"));//new ColorBackground(Color.BLUE, 800, 600);
		myButton = new Sprite(buttonImage, 240,220);
		myButton.setBackground(myBackground);
		resumeButton = new Sprite(getImage("images/resumeButton.png"),250,260);
		resumeButton.setBackground(myBackground);
		myFont = fontManager.getFont(getImages("images/largefont.png", 8, 12),
                " !\"#$%&'()*+,-./0123456789:;<=>?" +
                "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" +
                "`abcdefghijklmnopqrstuvwxyz{|}~~");
	}

	@Override
	public void render(Graphics2D g) {
		myBackground.render(g);
		myButton.render(g);
		resumeButton.render(g);
		myFont.drawString(g, myTitle, GameFont.CENTER, 200, 17, 200);
	}

	@Override
	public void update(long elapsedTime) {
		myBackground.update(elapsedTime);
		myButton.update(elapsedTime);
		resumeButton.update(elapsedTime);
		if(click() && checkPosMouse(myButton, true))
		{
			this.parent.nextGameID = (this.parent.getCurrentGameID()+1);
			this.finish();
		}
		if(click() && checkPosMouse(resumeButton, true))
		{
			((MyBallGame)this.parent).setResume(true);
			this.parent.nextGameID = ((LevelStateTable)((AbstractLevel)((MyBallGame)this.parent).getPrevGame()).getTable()).getLevel();
			System.out.println(((LevelStateTable)((AbstractLevel)((MyBallGame)this.parent).getPrevGame()).getTable()).getLevel());
			this.finish();
		}
	}

}
